﻿using System;
using System.IO.IsolatedStorage;
using System.Windows;
using System.Windows.Controls;
using mal.WP7.Framework.Controls;
using mal.WP7.GoogleAnalytics.Business.Resources;
using mal.WP7.GoogleAnalytics.ViewModels.Dashboard;
using Microsoft.Phone.Shell;
using Microsoft.Phone.Marketplace;
//using mal.WP7.GoogleAnalytics.Business.Resources;

namespace mal.WP7.GoogleAnalytics
{
    public partial class MainPage : NavigatePhoneApplicationPage
    {
        #region Fields
        private const int ConfigurationButtonIndex = 0;
        private const int AboutButtonIndex = 0;
        private static bool? isTrial = false;
        #endregion

        #region Construction / Destruction
        // Constructor
        public MainPage()
        {
            InitializeComponent();

            // Set the data context of the listbox control to the sample data
            DataContext = App.ViewModel;

            this.Loaded += new RoutedEventHandler(this.MainPage_Loaded);
        }
        #endregion

        #region Methods      
       
        #endregion

        #region Events
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            App.ViewModel.ResetSelection();
        }

        // Load data for the ViewModel Items
        private void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            ((ApplicationBarIconButton)this.ApplicationBar.Buttons[ConfigurationButtonIndex]).Text = ResourceText.MainPageParametersButton;

            ((ApplicationBarMenuItem)this.ApplicationBar.MenuItems[AboutButtonIndex]).Text = ResourceText.MainPageAboutButton;
 
            App.ViewModel.Cleanup();
            App.ViewModel.RegisterAccounts();
        }

        private void Panorama_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.AddedItems.Count > 0)
            {
                App.ViewModel.SelectedItem = (DashboardItemBase)e.AddedItems[0];
            }
        }

        private void OnApplicationBarIconButtonClick(object sender, System.EventArgs e)
        {
            NavigationService.Navigate(new Uri("/ConfigurationPage.xaml", UriKind.Relative));
        }

        private void OnAboutButtonClick(object sender, EventArgs e)
        {
            NavigationService.Navigate(new Uri("/AboutPage.xaml", UriKind.Relative));
        }
        #endregion
    }
}